//
//  QChargeBookView.m
//  QoilPublic
//
//  Created by 杨凯 on 16/8/15.
//  Copyright © 2016年 杨凯. All rights reserved.
//

#import "QChargeBookView.h"

@interface QChargeBookView()

@property (weak, nonatomic) IBOutlet UILabel *monthLabel;

@property (weak, nonatomic) IBOutlet UILabel *yearLabel;

@property (weak, nonatomic) IBOutlet UILabel *allSLabel;

@property (weak, nonatomic) IBOutlet UILabel *allZLabel;

@property (weak, nonatomic) IBOutlet UILabel *moneyLabel;

@property (weak, nonatomic) IBOutlet UIImageView *sProgress;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *sProgressConstr;

@property (weak, nonatomic) IBOutlet UIImageView *zProgress;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *zProgressConstr;

@end

@implementation QChargeBookView

- (void)awakeFromNib{

    [super awakeFromNib];
    self.sProgress.layer.cornerRadius = 6;
    self.zProgress.layer.cornerRadius = 6;
    self.allSLabel.font = [UIFont boldSystemFontOfSize:Ksize13];
    self.allZLabel.font = [UIFont boldSystemFontOfSize:Ksize13];
    self.monthLabel.font = [UIFont systemFontOfSize:22];
}

- (void)setArrData:(NSArray *)arrData{
    _arrData = arrData;
    QChargeBookModel *model = _arrData[0];
    _monthLabel.text = model.month;
    _yearLabel.text = model.year;
    
    double allz = 0.00;//支出
    double alls = 0.00;//收入
    double allsum = 0.00;//相差
    
    for(int i=0; i<_arrData.count; ++i){
        QChargeBookModel *m = _arrData[i];
        if([m.accountTypeBean.accountTypeId isEqualToString:@"0"]){//支出
            NSString *moneS = m.accountTypeBean.money;
            double z = moneS.doubleValue;
            allz+=z;
        }else if ([m.accountTypeBean.accountTypeId isEqualToString:@"1"]){//收入
            NSString *moneS = m.accountTypeBean.money;
            double s = moneS.doubleValue;
            alls+=s;
        }
    }
    _allZLabel.text = [NSString stringWithFormat:@"￥%.2f元",allz];
    _allSLabel.text = [NSString stringWithFormat:@"￥%.2f元",alls];
    
    allsum = alls-allz;//收入减去支出的
    _moneyLabel.textColor = [QColorUtility defaultBackColor];
    
    CGFloat consW = 0.0;
    if(iphone4x_3_5 || iphone5x_4_0){
        consW = 108;
    }else if (iphone6_4_7){
        consW = 150;
    }else if (iphone6Plus_5_5){
        consW = 180;
    }
    
    if(allsum >= 0){//收入大于支出
        _sProgressConstr.constant = consW;
        if(allz/alls*consW > 0){
            if(allz/alls*consW < 5){
                _zProgressConstr.constant = 5;
            }else{
                _zProgressConstr.constant = allz/alls*consW;
            }
        }else{
           _zProgressConstr.constant = 5;
        }
        
    }else{
        _zProgressConstr.constant = consW;
        if(alls/allz*consW > 0){
            if(alls/allz*consW < 5){
                _sProgressConstr.constant = 5;
            }else{
                _sProgressConstr.constant = alls/allz*consW;
            }
        }else{
            _sProgressConstr.constant = 5;
        }
    }
    _moneyLabel.text = [NSString stringWithFormat:@"￥%.2f元",allsum];
}

@end
